﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Golf.Model;
namespace Golf.BLL
{
	/// <summary>
	/// Golf_Coupons
	/// </summary>
	public partial class Golf_Coupons
	{
		private readonly Golf.DAL.Golf_Coupons dal=new Golf.DAL.Golf_Coupons();
		public Golf_Coupons()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int Id)
		{
			return dal.Exists(Id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Golf.Model.Golf_Coupons model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Golf.Model.Golf_Coupons model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			
			return dal.Delete(Id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return dal.DeleteList(Idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Golf.Model.Golf_Coupons GetModel(int Id)
		{
			
			return dal.GetModel(Id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Golf.Model.Golf_Coupons GetModelByCache(int Id)
		{
			
			string CacheKey = "Golf_CouponsModel-" + Id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(Id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Golf.Model.Golf_Coupons)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Golf.Model.Golf_Coupons> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Golf.Model.Golf_Coupons> DataTableToList(DataTable dt)
		{
			List<Golf.Model.Golf_Coupons> modelList = new List<Golf.Model.Golf_Coupons>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Golf.Model.Golf_Coupons model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Golf.Model.Golf_Coupons();
					if(dt.Rows[n]["Id"]!=null && dt.Rows[n]["Id"].ToString()!="")
					{
						model.Id=int.Parse(dt.Rows[n]["Id"].ToString());
					}
					if(dt.Rows[n]["CouponsType"]!=null && dt.Rows[n]["CouponsType"].ToString()!="")
					{
						if((dt.Rows[n]["CouponsType"].ToString()=="1")||(dt.Rows[n]["CouponsType"].ToString().ToLower()=="true"))
						{
						model.CouponsType=true;
						}
						else
						{
							model.CouponsType=false;
						}
					}
					if(dt.Rows[n]["CouponsNumber"]!=null && dt.Rows[n]["CouponsNumber"].ToString()!="")
					{
					model.CouponsNumber=dt.Rows[n]["CouponsNumber"].ToString();
					}
					if(dt.Rows[n]["CouponsPassWord"]!=null && dt.Rows[n]["CouponsPassWord"].ToString()!="")
					{
					model.CouponsPassWord=dt.Rows[n]["CouponsPassWord"].ToString();
					}
					if(dt.Rows[n]["CouponsFacevalue"]!=null && dt.Rows[n]["CouponsFacevalue"].ToString()!="")
					{
						model.CouponsFacevalue=decimal.Parse(dt.Rows[n]["CouponsFacevalue"].ToString());
					}
					if(dt.Rows[n]["IsRestriction"]!=null && dt.Rows[n]["IsRestriction"].ToString()!="")
					{
						if((dt.Rows[n]["IsRestriction"].ToString()=="1")||(dt.Rows[n]["IsRestriction"].ToString().ToLower()=="true"))
						{
						model.IsRestriction=true;
						}
						else
						{
							model.IsRestriction=false;
						}
					}
					if(dt.Rows[n]["CouponsRestriction"]!=null && dt.Rows[n]["CouponsRestriction"].ToString()!="")
					{
					model.CouponsRestriction=dt.Rows[n]["CouponsRestriction"].ToString();
					}
					if(dt.Rows[n]["CouponsState"]!=null && dt.Rows[n]["CouponsState"].ToString()!="")
					{
						model.CouponsState=int.Parse(dt.Rows[n]["CouponsState"].ToString());
					}
					if(dt.Rows[n]["UserServiceTime"]!=null && dt.Rows[n]["UserServiceTime"].ToString()!="")
					{
						model.UserServiceTime=DateTime.Parse(dt.Rows[n]["UserServiceTime"].ToString());
					}
					if(dt.Rows[n]["PastdueTime"]!=null && dt.Rows[n]["PastdueTime"].ToString()!="")
					{
						model.PastdueTime=DateTime.Parse(dt.Rows[n]["PastdueTime"].ToString());
					}
					if(dt.Rows[n]["UserId"]!=null && dt.Rows[n]["UserId"].ToString()!="")
					{
						model.UserId=int.Parse(dt.Rows[n]["UserId"].ToString());
					}
					if(dt.Rows[n]["UserOrderId"]!=null && dt.Rows[n]["UserOrderId"].ToString()!="")
					{
						model.UserOrderId=int.Parse(dt.Rows[n]["UserOrderId"].ToString());
					}
					if(dt.Rows[n]["UserOrderNumber"]!=null && dt.Rows[n]["UserOrderNumber"].ToString()!="")
					{
					model.UserOrderNumber=dt.Rows[n]["UserOrderNumber"].ToString();
					}
					if(dt.Rows[n]["CreateTime"]!=null && dt.Rows[n]["CreateTime"].ToString()!="")
					{
						model.CreateTime=DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

		#endregion  Method
	}
}

